<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>挂靠公司授信信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
	 <form id="prj_lnk_comp_cr_lim_form">
                        <div class="fieldset1 tabel_col clearFix">
		               		  <div class="fieldBox col_50">
				                    <div class="label">当前实际敞口（元）</div>
				                    <div class="field">
				                          <span style="color: red" id="currCrAmt">
				                       <c:if test="${currCrAmt!=0}">
		                    		<fmt:formatNumber type="number" value="${currCrAmt}"  pattern=".00"/>
		                  			  </c:if>
		                  			  <c:if test="${currCrAmt==0}">0</c:if>
		                    </span>
				                    </div>
		               		 </div>
                        
		               		 <div class="fieldBox col_50">
		               		    <div class="label"></div>
				                    <div class="field">
						                          <input type="checkbox" id="isLimit" name="isLimit"  onchange="setCrAmtValue();" />取消敞口限制
				                    </div>
		               		 </div>
		               		  <div class="fieldBox col_50">
                                <div class="label">开始时间</div>
                                <div class="field"> 
                              		<input name="startDt" id="startDt" type="text"   class="ui-datepicker"  value=""   validate="{required:true}">
                               		<span class="requiredSymbol" >*</span>
                                </div>
                            </div>
                              <div class="fieldBox col_50">
                                <div class="label">结束时间</div>
                                <div class="field"> 
                              		<input name="endDt"  id="endDt" type="text"  class="ui-datepicker"  value=""   validate="{required:true}">
                               		<span class="requiredSymbol" >*</span>
                                </div>
                            </div>
                              <div class="fieldBox col_50">
                                <div class="label">敞口金额（元）</div>
                                <div class="field"> 
                              		<input name="crAmt" id="crAmt"  type="text"    class="ui-textbox"  value=""   validate="{required:true}">
                               		<span class="requiredSymbol" >*</span>
                                </div>
                            </div>
                             <div class="fieldBox col_100" style="display:none;">
								<div class="field">
								    <input name="crLimitId"  id="crLimitId" type="text" class="ui-textbox" value="" >
								</div>
							</div>
                            </div>
                    </form>
                    </div>
                    </div>
	<script>
	
	var currCrAmtValue='${currCrAmt}';
	//$("#currCrAmt").text((parseFloat(currCrAmtValue/100)).toFixed(2));
	var isProvMgr ='${isProvMgr}';
	var compId='${compId}';
		$(function() {
			 var ligerForm = liger.get("prj_lnk_comp_cr_lim_form");
		   $("#prj_lnk_comp_cr_lim_form").ligerForm({
                validate: true
           });
		});
		
		function setCrAmtValue(){
			var valid = $("#isLimit")[0].value;
			var flag = $('[name="isLimit"]').prop('checked');
			if(flag){
				if(valid){
				$("#crAmt").val(0);
				if($("#crAmt")){
					  liger.get("crAmt").setDisabled();
				}
				}
			}else{
				$("#crAmt").val("");
				if($("#crAmt")){
					  liger.get("crAmt").setEnabled();
				}
			}
		}
		
		frameElement.dialog.onCancel = function(){
			 parent.$.ligerDialog.close();
			 parent.$(".l-dialog,.l-window-mask").css("display","none"); 
		 }
		 frameElement.dialog.onSave=function(){
			 frameElement.dialog.disabledBtns();
			  var ligerForm = liger.get("prj_lnk_comp_cr_lim_form");
			 if (!ligerForm.valid()) {
		            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
		            return false; //验证不通过，不执行以下代码
		        }
			 if(isProvMgr){
			        var data = ligerForm.getData();
			        data["compId"] = compId;
				    data["currCrAmt"] =  $("#currCrAmt").text();
			        var url = '<%=path%>/project/prjLnkCompCrLim/addAndApply.do';
			        var wait_dialog;
			        $.ajax({
			    		type: 'post',
			    		dataType:'json',
			    		data:data,
			    		url: url,
			    		beforeSend: function(){
					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					     },
			    		success:function(msg){
			    			 wait_dialog.close();
			    			 if(msg.success == 1){
			    				 $("#crLimitId").val(msg.data);
			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
			    				 parent.$.ligerDialog.close();
			     				parent.$(".l-dialog,.l-window-mask").css("display","none"); 
			    			 }else{
			    				 wait_dialog.close();
			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			    			 }
			    		}
			    	});
			        
			 }else{
				 $.ligerDialog.confirm("确定要保存并发起挂靠公司敞口流程吗？", function (flag) {
						if(flag == false)return;
						data["compId"] = $("#compId").val();
					    data["currCrAmt"] =  $("#currCrAmt").val();
				        var url = '<%=path%>/project/prjLnkCompCrLim/add.do';
				        var wait_dialog;
				        $.ajax({
				    		type: 'post',
				    		dataType:'json',
				    		data:data,
				    		url: url,
				    		beforeSend: function(){
						          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						     },
				    		success:function(msg){
				    			 wait_dialog.close();
				    			 if(msg.success == 1){
				    				 $("#crLimitId").val(msg.data);
				    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
				    				 parent.$.ligerDialog.close();
				     				parent.$(".l-dialog,.l-window-mask").css("display","none"); 
				    			 }else{
				    				 wait_dialog.close();
				    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				    			 }
				    		}
				    	});
				        
					});
			 }
			
		}
	</script>

</body>
</html>